

//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/CallBack.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function CallBack(){}
CallBack.create = function( p_func, p_context, p_args )
{
	var func = function()
	{
		if( arguments != undefined )
		{
			//if( typeof( p_args ) == "Array" )
			//{
				//p_args.concat(arguments);
			//}
			//else
			//{
				p_args = arguments;
			//}
		}
		
		p_func.apply( p_context, p_args );
	};
	
	return func;
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/Main.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

 
 
function Main()
{
	this.init();
}

Main.prototype.init = function()
{
	ApplicationFacade.getInstance().init();
	ApplicationFacade.getInstance().sendNotification( ApplicationNotification.START_APP ); 	
};



window.onload = function()
{
	POO.run();
	new Main();
};


window.requestAnimationFrame = (function () {

  return window.requestAnimationFrame || //Chromium 
  window.webkitRequestAnimationFrame || //Webkit
  window.mozRequestAnimationFrame || //Mozilla Geko
  window.oRequestAnimationFrame || //Opera Presto
  window.msRequestAnimationFrame || //IE Trident?

  function (callback, element) { //Fallback function
    window.setTimeout(callback, 1);
  }
 
})();







//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/const/ApplicationNotification.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function ApplicationNotification(){}

	// static
	
	ApplicationNotification.START_APP 				= "startApp";
	ApplicationNotification.LOAD_DATA_COMPLETE	 	= "loadDataComplete";
	ApplicationNotification.LOAD_DATA_PROGRESS	 	= "loadDataProgress";
	ApplicationNotification.SELECT_ANIMATION	 	= "selectAnimation";
	ApplicationNotification.SELECT_LAYER	 		= "selectLayer";
	ApplicationNotification.ADD_LAYER	 			= "addLayer";
	ApplicationNotification.REMOVE_LAYER	 		= "removeLayer";
	ApplicationNotification.SELECT_MAP	 			= "selectMap";
	ApplicationNotification.ADD_MAP	 				= "addMap";
	ApplicationNotification.REMOVE_MAP	 			= "removeMap";
	ApplicationNotification.ADD_ANIMATION	 		= "addAnimation";
	ApplicationNotification.CLEAN_LAYERS	 		= "cleanLayers";
	ApplicationNotification.CLEAN_MAP	 			= "cleanMap";
	ApplicationNotification.DISPLAY_MAP_LAYERS	 	= "displayMapLayers";
	ApplicationNotification.DISPLAY_MAPS	 		= "displayMaps";
	ApplicationNotification.LOAD_MAPS_DATA	 		= "loadMapsData";
	ApplicationNotification.LOAD_PROJECT	 		= "loadProject";
	ApplicationNotification.UNLOAD_PROJECT	 		= "unloadProject";
	ApplicationNotification.LOAD_PROJECT_COMPLETE	= "loadProjectComplete";
	ApplicationNotification.SAVE_PROJECT			= "SaveProject";
	ApplicationNotification.OPEN_PROJECT_LAYOUT		= "openProjectLayout";



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/AddAnimationCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function AddAnimationCommand(){}; 
POO.extend( AddAnimationCommand, Command );



AddAnimationCommand.prototype.execute = function( p_notificationType, p_data )
{
	
	var facade = ApplicationFacade.getInstance(); 
	
	var appProxy = facade.getProxy( ApplicationProxy.NAME );
	var mapProxy = facade.getProxy( MapProxy.NAME );
	var animProxy = facade.getProxy( AnimationProxy.NAME );
	
	var currentMap = appProxy.currentMap;
	var currentLayer = appProxy.currentLayer;
	
	var mapVO = mapProxy.getMapVOById( currentMap );
	
	if( mapVO == null )
		return;
	
	var layerVO = mapVO.getLayerVOById( currentLayer );
	
	if( layerVO == null )
		return;
	
	var animVO = animProxy.getAnimationVOById(p_data.animId);
	
	if( animVO == null )
		return;
	
	//p_data.layerId
	//x,y,z,width,height,alpha,animated:true||false,texId||animId,movable:true||false
	layerVO.displayList.push(
	
				[p_data.x, p_data.y, 0, animVO.width, animVO.height, 1, true, p_data.animId, true ]
				
	);
	
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/AddLayerCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function AddLayerCommand(){}; 
POO.extend( AddLayerCommand, Command );



AddLayerCommand.prototype.execute = function( p_notificationType, p_data )
{
	var facade = ApplicationFacade.getInstance();
	
	var appProxy = facade.getProxy( ApplicationProxy.NAME );
	var mapProxy = facade.getProxy( MapProxy.NAME );
	var currentMap = appProxy.currentMap;
	var vo = mapProxy.getMapVOById( currentMap );
	
	var layerVO = new LayerVO();
	layerVO.name = p_data;
	vo.layers.push( layerVO );
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/AddMapCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function AddMapCommand(){}; 
POO.extend( AddMapCommand, Command );



AddMapCommand.prototype.execute = function( p_notificationType, p_data )
{
	var facade = ApplicationFacade.getInstance();
	var mapProxy = facade.getProxy( MapProxy.NAME );
	var vo = null;
	vo = new MapVO();
	vo.name = p_data;
	vo.layers = new Array();
			
	mapProxy.addMapVO(vo);
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/LoadMapsCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function LoadMapsCommand(){}; 
POO.extend( LoadMapsCommand, Command );



LoadMapsCommand.prototype.execute = function( p_notificationType, p_data )
{
	
	var facade = ApplicationFacade.getInstance(); 
	var mapProxy = facade.getProxy( MapProxy.NAME );
	var vos = mapProxy.getData();
	
	var i = 0;
	var max = vos.length;
	
	facade.sendNotification( ApplicationNotification.DISPLAY_MAPS );
	
	for( i = 0; i < max; i++ )
	{
		facade.sendNotification( ApplicationNotification.SELECT_MAP, vos[i].name );
	}
	
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/LoadProjectCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function LoadProjectCommand(){}; 
POO.extend( LoadProjectCommand, Command );



LoadProjectCommand.prototype.execute = function( p_notificationType, p_data )
{
	var facade = ApplicationFacade.getInstance(); 
	var appProxy = facade.getProxy( ApplicationProxy.NAME );
	// unload previous project
	facade.sendNotification( ApplicationNotification.UNLOAD_PROJECT );
	appProxy.loadProject( p_data );
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/RemoveLayerCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function RemoveLayerCommand(){}; 
POO.extend( RemoveLayerCommand, Command );



RemoveLayerCommand.prototype.execute = function( p_notificationType, p_data )
{
	var facade = ApplicationFacade.getInstance();
	var appProxy = facade.getProxy( ApplicationProxy.NAME );
	var mapProxy = facade.getProxy( MapProxy.NAME );
	var vo = mapProxy.getMapVOById(appProxy.currentMap);
	vo.removeLayerVOById( appProxy.currentLayer );
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/RemoveMapCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function RemoveMapCommand(){}; 
POO.extend( RemoveMapCommand, Command );



RemoveMapCommand.prototype.execute = function( p_notificationType, p_data )
{
	var facade = ApplicationFacade.getInstance();
	var appProxy = facade.getProxy( ApplicationProxy.NAME );
	var mapProxy = facade.getProxy( MapProxy.NAME );
	var vo = mapProxy.getMapVOById(appProxy.currentMap);
	var layerVO = null;
	
	var i = vo.layers.length;
	
	
	while( --i > -1 )
	{
		layerVO = vo.layers[i];
		
		appProxy.currentLayer = layerVO.name;
		facade.sendNotification( ApplicationNotification.REMOVE_LAYER, layerVO.name );
	}
	
	mapProxy.removeMapVOById(appProxy.currentMap);
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/SaveProjectCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function SaveProjectCommand(){}; 
POO.extend( SaveProjectCommand, Command );

// p_data.name

SaveProjectCommand.prototype.execute = function( p_notificationType, p_data )
{
	
	var facade = ApplicationFacade.getInstance(); 
	
	var appProxy = facade.getProxy( ApplicationProxy.NAME );
	var mapProxy = facade.getProxy( MapProxy.NAME );
	var animProxy = facade.getProxy( AnimationProxy.NAME );
	var texProxy = facade.getProxy( TextureProxy.NAME );
	
	
	var currentProject = appProxy.getProjectName();
	var maps = mapProxy.getData();
	
	
	var data = 	"(function(){";
		data += "\n\tvar project = new Object();";
		data += "\n\tproject.name = \""+p_data.name+"\";";
		
		data += "\n\n\tproject.getAnimationsList = function(){";
		data += this.exportAnimations(animProxy);
		data += "\n\t};";
		
		data += "\n\n\tproject.getTexturesList = function(){";
		data += this.exportTextures(texProxy);
		data += "\n\t};";
		
		data += "\n\n\tproject.getMapsList = function(){";
		data += this.exportMaps(maps);
		data += "\n\t};";
		
		data += "\n\n\treturn project;})();";
	
	var url = "./assets/projects/"+p_data.name+".js";
	var sender = new Sender();
	sender.sendAndLoad("./service/saver.php", "url="+url+"&save="+data, "POST", true);
};

SaveProjectCommand.prototype.exportTextures = function( p_proxy )
{
	return "return [\n\t\t'"+p_proxy.getTexturesList().join("',\n\t\t'")+"'];";
};

SaveProjectCommand.prototype.exportAnimations = function( p_proxy )
{
	
	var anims = p_proxy.getData();
	var frameObj = null;
	var vo = null;
	var i = 0;
	var j = 0;
	var max = anims.length;
	var frames = anims.length;
	var data = "\n\n\treturn [";
	
	for( i = 0; i < max; i++ )
	{
		vo = anims[i];
		
		if( i > 0 )
			data += ",";
		
		data += "\n\t\t{";
		
		data += '\n\t\t\t"name":"'+vo.name+'",';
		data += '\n\t\t\t"width":'+vo.width+',';
		data += '\n\t\t\t"height":'+vo.height+',';
		data += '\n\t\t\t"animTime":'+vo.animTime+',';
		data += '\n\t\t\t"frames":[';
		
		max2 = vo.frames.length;
		
		for( j = 0; j < max2; j++ )
		{
			frameObj = vo.frames[j];
			
			if( j > 0 )
				data += ",";
				
			data+= '\n\t\t\t\t{"uv":['+frameObj.uv.join()+'],"tex":'+frameObj.tex+'}';
		}
		
		data += '\n\n\t\t]}'
	}
	
	data += "\n\n\t];";
	
	return data;
};

SaveProjectCommand.prototype.exportMaps = function( p_maps )
{
	var i = 0;
	var max = p_maps.length;
	var layerVO = null;
	var data = "\n\n\treturn [";
	
	for( i = 0; i < max; i++ )
	{
		mapVO = p_maps[i];
		
		if( i > 0 )
		{
			data += ",";
		}
		data +=  '\n\t\t{"name":"'+mapVO.name+'","type":"isomap","layers":['+this.exportLayers(mapVO.layers)+']}';
	}
	
	data += "\n\n\t];";
	
	return data;
};

SaveProjectCommand.prototype.exportLayers = function( p_layers )
{
	var i = 0;
	var max = p_layers.length;
	var layerVO = null;
	var data = "";
	
	for( i = 0; i < max; i++ )
	{
		layerVO = p_layers[i];
		
		if( i > 0 )
		{
			data += ",";
		}
		data +=  '\n\t\t\t{"lazy":'+layerVO.lazy+',"sortFunc":'+layerVO.sortFunc+',"sortArgs":'+layerVO.sortArgs+',"name":"'+layerVO.name+'","displayList":['+this.exportDisplayList(layerVO.displayList)+'\n\t\t]}';
	}
	
	return data;
							
};

SaveProjectCommand.prototype.exportDisplayList = function( p_displayList )
{
	
	//x,y,z,width,height,alpha,animated:true||false,texId||animId,movable:true||false
	
	var i = 0;
	var j = 0;
	var max = p_displayList.length;
	var max2 = p_displayList.length;
	var spr = null;
	var data = "";
	
	for( i = 0; i < max; i++ )
	{
		spr = p_displayList[i];
		
		if( i > 0 )
		{
			data += ",";
		}
		
		max2 = spr.length;
		data +=  '\n\t\t\t[';
		
		for( j = 0; j < max2; j++ )
		{
			if( j > 0 )
			{
				data += ",";
			}
			
			if( typeof( spr[j] ) == "string" )
			{
				data += '"'+spr[j]+'"';
			}
			else
			{
				data += spr[j];
			}
		}
		
		data += ']';
		
	}
	
	return data;
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/SelectMapCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function SelectMapCommand(){}; 
POO.extend( SelectMapCommand, Command );



SelectMapCommand.prototype.execute = function( p_notificationType, p_data )
{
	var facade = ApplicationFacade.getInstance();
	var appProxy = facade.getProxy( ApplicationProxy.NAME );
	var mapProxy = facade.getProxy( MapProxy.NAME );
	appProxy.currentMap = p_data;
	
	facade.sendNotification( ApplicationNotification.CLEAN_MAP );
	facade.sendNotification( ApplicationNotification.CLEAN_LAYERS );
	facade.sendNotification( ApplicationNotification.DISPLAY_MAP_LAYERS );
	facade.sendNotification( ApplicationNotification.DISPLAY_MAP_ANIM );
	
	//var mapVO = mapProxy.getMapVOById(appProxy.currentMap);
	//var layerVO = null;
	//var i = 0;
	//var j = 0;
	//var max = mapVO.layers.length;
	//var max2 = 0;
	//var body = null;
	//var disp = null;
	//
	//for( i = 0; i < max; i++ )
	//{
		//layerVO = mapVO.layers[i];
		//facade.sendNotification( ApplicationNotification.ADD_LAYER, layerVO.name );
		//
		//
		//disp = layerVO.displayList;
		//max2 = disp.length;
		//
		//for( j = 0; j < max2; j++ )
		//{
			//body = new Object();
			//body.animId = disp[j][7];
			//body.x = disp[j][0];
			//body.y = disp[j][1];
			//body.layerId = layerVO.name;
			//
			//facade.sendNotification( ApplicationNotification.ADD_ANIMATION, body );		
		//}
	//}
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/StartApplicationCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function StartApplicationCommand(){}; 
POO.extend( StartApplicationCommand, Command );



StartApplicationCommand.prototype.execute = function( p_notificationType, p_data )
{
	var menumediator 	= new ActionMenuMediator(document.getElementById("topMenu"));
	var mapmediator 	= new MapMediator(document.getElementById("uiContainer"));
	var laymediator 	= new LayersMediator(document.getElementById("layersWindow"));
	var maplaymediator 	= new MapLayersMediator(document.getElementById("mapsWindow"));
	var libmediator 	= new LibraryMediator(document.getElementById("libraryWindow"));
	var appproxy 		= new ApplicationProxy();
	var texproxy		= new TextureProxy();
	var animProxy		= new AnimationProxy();
	var mapProxy		= new MapProxy();
	
	ApplicationFacade.getInstance().registerMediator( ActionMenuMediator.NAME, menumediator );
	ApplicationFacade.getInstance().registerMediator( MapMediator.NAME, mapmediator );
	ApplicationFacade.getInstance().registerMediator( MapLayersMediator.NAME, maplaymediator );
	ApplicationFacade.getInstance().registerMediator( LayersMediator.NAME, laymediator );
	ApplicationFacade.getInstance().registerMediator( LibraryMediator.NAME, libmediator );
	ApplicationFacade.getInstance().registerProxy( AnimationProxy.NAME, animProxy );
	ApplicationFacade.getInstance().registerProxy( TextureProxy.NAME, texproxy );
	ApplicationFacade.getInstance().registerProxy( ApplicationProxy.NAME, appproxy );
	ApplicationFacade.getInstance().registerProxy( MapProxy.NAME, mapProxy );
	
	
	ApplicationFacade.getInstance().sendNotification( ApplicationNotification.LOAD_PROJECT, './assets/projects/default.js' );
	
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/controller/UnloadProjectCommand.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function UnloadProjectCommand(){}; 
POO.extend( UnloadProjectCommand, Command );



UnloadProjectCommand.prototype.execute = function( p_notificationType, p_data )
{
	var facade = ApplicationFacade.getInstance(); 
	var mapProxy = facade.getProxy(MapProxy.NAME);
	var appProxy = facade.getProxy(ApplicationProxy.NAME);
	
	var maps = mapProxy.getData();
	var i = 0;
	var max = maps.length;
	var vo = null;
	
	for( i = 0; i < max; i++ )
	{
		vo = maps[i];
		appProxy.currentMap = vo.name;
		
		facade.sendNotification( ApplicationNotification.REMOVE_MAP, vo.name );
	}
	
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/facade/ApplicationFacade.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

	
	
function ApplicationFacade(){}
POO.extend( ApplicationFacade, Facade );


	// static
	
	ApplicationFacade._instance = null;

	ApplicationFacade.getInstance = function()
	{
		ApplicationFacade._instance = ApplicationFacade._instance || new ApplicationFacade();
		return ApplicationFacade._instance;
	};
	
	
	// public
	
	ApplicationFacade.prototype.init = function()
	{
		this._super.init.apply( this );
		
		this.registerCommand( ApplicationNotification.START_APP, StartApplicationCommand );
		this.registerCommand( ApplicationNotification.ADD_LAYER, AddLayerCommand);
		this.registerCommand( ApplicationNotification.REMOVE_LAYER, RemoveLayerCommand);
		this.registerCommand( ApplicationNotification.ADD_MAP, AddMapCommand);
		this.registerCommand( ApplicationNotification.REMOVE_MAP, RemoveMapCommand);
		this.registerCommand( ApplicationNotification.SELECT_MAP, SelectMapCommand);
		this.registerCommand( ApplicationNotification.ADD_ANIMATION, AddAnimationCommand );
		this.registerCommand( ApplicationNotification.LOAD_MAPS_DATA, LoadMapsCommand );
		this.registerCommand( ApplicationNotification.UNLOAD_PROJECT, UnloadProjectCommand );
		this.registerCommand( ApplicationNotification.LOAD_PROJECT, LoadProjectCommand );
		this.registerCommand( ApplicationNotification.SAVE_PROJECT, SaveProjectCommand );
	};
	
	



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/model/AnimationProxy.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function AnimationProxy()
{
	this.init( AnimationProxy.NAME, new Array() );
}

POO.extend( AnimationProxy, Proxy );


	// static
	
	AnimationProxy.NAME = "AnimationProxy";
	
	//public
	
	AnimationProxy.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [ p_name, p_data ] );
		this.listenNotifications();
	};
	
	AnimationProxy.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.LOAD_PROJECT_COMPLETE, this.onNotification );
	};

	AnimationProxy.prototype.onNotification = function( p_notificationType, p_data )
	{
		switch ( p_notificationType )
		{
			case ApplicationNotification.LOAD_PROJECT_COMPLETE:	
				this._parseAnimationData(); 
				break;
		}
	};
	
	AnimationProxy.prototype.getAnimationVOById = function( p_id )
	{
		var vo = null;
		var i = 0;
		var max = this._data.length;
		
		for( ; i < max; i++ )
		{
			vo = this._data[i];
			if( vo.name == p_id )
				return vo;
		}
		
		return null;
	};

	
	// private
	AnimationProxy.prototype._parseAnimationData = function()
	{
		var proxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var data = proxy.getAnimationsList();
		var i = 0;
		var max = data.length;
		var vo = null;
		var obj = null;
		
		for( ; i < max; i++ )
		{
			obj = data[i];
			vo = new AnimationVO();
			vo.name = obj.name;
			vo.width = obj.width;
			vo.height = obj.height;
			vo.animTime = obj.animTime;
			vo.frames = obj.frames;
			
			this._data.push( vo );
		}
	};
	

	



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/model/ApplicationProxy.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function ApplicationProxy()
{
	this.init( ApplicationProxy.NAME, new Array() );
}

POO.extend( ApplicationProxy, Proxy );


	// static
	ApplicationProxy.NAME = "ApplicationProxy";


	//public
	ApplicationProxy.prototype.currentAnim 		= "";
	ApplicationProxy.prototype.currentLayer 	= "";
	ApplicationProxy.prototype.currentMap 		= "";
	ApplicationProxy.prototype._currentProject  = null;
	ApplicationProxy.prototype._loader			= null;
	
	
	ApplicationProxy.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [ p_name, p_data ] );
		this.listenNotifications();
		this._loader = new Loader();
		this._loader.signal.addListener( Loader.LOAD_COMPLETE, this._loadProjectCompleteHandler, this );
	};
	
	ApplicationProxy.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.SELECT_ANIMATION, this.onNotification );
		this.addNotificationListener( ApplicationNotification.SELECT_LAYER, 	this.onNotification );
		this.addNotificationListener( ApplicationNotification.SELECT_MAP, 		this.onNotification );
	};

	ApplicationProxy.prototype.onNotification = function( p_notificationType, p_data )
	{
		switch ( p_notificationType )
		{
			case ApplicationNotification.SELECT_ANIMATION:	this.currentAnim 	= p_data;	break;
			case ApplicationNotification.SELECT_LAYER:		this.currentLayer 	= p_data;	break;
			case ApplicationNotification.SELECT_MAP:		this.currentMap 	= p_data;	break;
		}
	};
	
	
	ApplicationProxy.prototype.loadProject = function( p_url )
	{
		this._loader.load( p_url );
	};
	
	ApplicationProxy.prototype._loadProjectCompleteHandler = function()
	{
		try
		{
			this._currentProject = eval( this._loader.getData() );
		}
		catch(error)
		{
			this._currentProject = this.getDefaultProject();
		}
		
		this.getFacade().sendNotification( ApplicationNotification.LOAD_PROJECT_COMPLETE );
	};
	
	ApplicationProxy.prototype.getAnimationsList = function()
	{
		return this._currentProject.getAnimationsList();
	};
	
	ApplicationProxy.prototype.getTexturesList = function()
	{
		return this._currentProject.getTexturesList();
	};
	
	ApplicationProxy.prototype.getMapsList = function()
	{
		return this._currentProject.getMapsList();
	};
	
	ApplicationProxy.prototype.getProjectName = function()
	{
		return this._currentProject.name;
	};
	
	ApplicationProxy.prototype.getDefaultProject = function()
	{
		var project = new Object();
		project.name = "default";

		project.getAnimationsList = function(){return [];};
		project.getTexturesList = function(){return [];};
		project.getMapsList = function(){return [];};

		return project;
	};

	
	



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/model/MapProxy.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function MapProxy()
{
	this.init( MapProxy.NAME, new Array() );
}

POO.extend( MapProxy, Proxy );


	// static
	
	MapProxy.NAME = "MapProxy";
	
	//public
	
	MapProxy.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [ p_name, p_data ] );
		this.listenNotifications();
	};
	
	MapProxy.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.LOAD_PROJECT_COMPLETE, this.onNotification );
	};

	MapProxy.prototype.onNotification = function( p_notificationType, p_data )
	{
		switch ( p_notificationType )
		{
			case ApplicationNotification.LOAD_PROJECT_COMPLETE:	
				this._parseMapData(); 
				break;
		}
	};
	
	MapProxy.prototype.getMapVOById = function( p_id )
	{
		var vo = null;
		var i = 0;
		var max = this._data.length;
		
		for( ; i < max; i++ )
		{
			vo = this._data[i];
			if( vo.name == p_id )
				return vo;
		}
		
		return null;
	};
	
	MapProxy.prototype.removeMapVOById = function( p_id )
	{
		var vo = this.getMapVOById(p_id);
		var index = -1;
		if( vo != null )
		{
			index = this._data.indexOf(vo);
			this._data.splice( index, 1 );
		}
	};
	
	MapProxy.prototype.addMapVO = function( p_vo )
	{
		this._data.push( p_vo );
	};

	
	// private
	MapProxy.prototype._parseMapData = function()
	{
		var proxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var data = proxy.getMapsList();
		var i = 0;
		var j = 0;
		var max = data.length;
		var ma2 = data.length;
		var vo = null;
		var layerVO = null;
		var obj = null;
		var obj2 = null;
		
		for( ; i < max; i++ )
		{
			obj = data[i];
			vo = new MapVO();
			
			vo.layers = new Array();
			max2 = obj.layers.length;
			
			for( j = 0; j < max2; j++ )
			{
				obj2 = obj.layers[j];
				layerVO = new LayerVO();
				layerVO.name = obj2.name;
				layerVO.lazy = obj2.lazy;
				layerVO.sortFunc = obj2.sortFunc;
				layerVO.sortArgs = obj2.sortArgs;
				layerVO.displayList = obj2.displayList;
				
				vo.layers.push( layerVO );
			}
			
			vo.name = obj.name;
			vo.type = obj.type;
			this._data.push( vo );
		}
		
	};
	

	



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/model/TextureProxy.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function TextureProxy()
{
	this.init( TextureProxy.NAME, new Array() );
}

POO.extend( TextureProxy, Proxy );


	// static
	
	TextureProxy.NAME = "TextureProxy";

	
	//private
	TextureProxy.prototype._loader 	= null;
	TextureProxy.prototype._list 	= null;
	
	//public
	
	TextureProxy.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [ p_name, p_data ] );
		this._loader = new ImageLoader();
		this._loader.signal.addListener( ImageLoader.LOAD_PROGRESS, this._loadProgressHandler, this );
		this._loader.signal.addListener( ImageLoader.LOAD_COMPLETE, this._loadCompleteHandler, this );
		this.listenNotifications();
	};
	
	TextureProxy.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.LOAD_PROJECT_COMPLETE, this.onNotification );
	};

	TextureProxy.prototype.onNotification = function( p_notificationType, p_data )
	{
		switch ( p_notificationType )
		{
			case ApplicationNotification.LOAD_PROJECT_COMPLETE:	
				this._loadTextures(); 
				break;
		}
	};
	
	
	// private
	TextureProxy.prototype._loadTextures = function( p_from, p_to )
	{
		this._list = new Array();
		this._loader.clean();
		var proxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var data = proxy.getTexturesList();
		var i = 0;
		var max = data.length;
		
		for( ; i < max; i++ )
		{
			this._loader.addFile(data[i], i);
			this._list.push( data[i] );
		}
		
		this._loader.load();
	};
	
	TextureProxy.prototype._loadProgressHandler = function()
	{
		var progression = this._loader.getProgression();
		this.getFacade().sendNotification(ApplicationNotification.LOAD_DATA_PROGRESS, {"progression":progression});
	};
	
	TextureProxy.prototype._loadCompleteHandler = function()
	{
		var appProxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var manager = TextureManager.getInstance();
		var data = this._loader.getData();
		var texture = null;
		var id = null;
		
		for( id in data )
		{
			texture = SmartTexture.createTexture();
			texture.id = parseInt(id);
			texture.data = data[id];
			texture.type = Texture2D.BMP_TEXTURE;
			manager.addTexture( texture );
		}
		
		this.getFacade().sendNotification(ApplicationNotification.LOAD_DATA_COMPLETE);
	};
	
	TextureProxy.prototype.getTexturesList = function()
	{
		return this._list;
	};

	
	



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/model/texture/SmartTexture.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function SmartTexture(){}; 
POO.extend( SmartTexture, Texture2D );


	// static
	SmartTexture._instances = new Array();

	SmartTexture.createTexture = function()
	{
		var texture = null;
		
		if( SmartTexture._instances.length > 0 )
		{
			texture = SmartTexture._instances.shift();
		}
		else
		{
			texture = new SmartTexture();
		}
		
		return texture;
	};
	
	
	//public
	SmartTexture.prototype.recycle = function()
	{
		this.data = null;
		this.url = null;
		this.id = -1;
		this.color = "#000000";
		this.type = Texture2D.COLOR_TEXTURE;
		
		SmartTexture._instances.push( this );
	};
	
	



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/model/vo/AnimationVO.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function AnimationVO(){}


AnimationVO.prototype.name = null;
AnimationVO.prototype.width = 0;
AnimationVO.prototype.height = 0;
AnimationVO.prototype.animTime = 16;

AnimationVO.prototype.frames = null;

//{"uv":[0.25, 	0.25, 	0.5, 	0.5	],	"tex":2},
//{"uv":[0.5, 	0.5, 	0.75, 	0.75],	"tex":2},
//{"uv":[0.5, 	0.5, 	0.75, 	0.75],	"tex":2},
//{"uv":[0.75, 	0.75, 	1, 		1],		"tex":2},
//{"uv":[0, 		0, 		1, 		1],		"tex":2}



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/model/vo/LayerVO.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function LayerVO()
{
	this.displayList = new Array();
}

LayerVO.prototype.lazy 			= false;
LayerVO.prototype.sortFunc 		= null;
LayerVO.prototype.sortArgs 		= null;
LayerVO.prototype.name 			= "";
LayerVO.prototype.displayList 	= null;



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/model/vo/MapVO.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function MapVO()
{
	this.layers = new Array();
}


MapVO.prototype.name = "";
MapVO.prototype.type = "";
MapVO.prototype.layers = null;

MapVO.prototype.removeLayerVOById = function( p_id )
{
	var i = 0;
	var max = this.layers.length;
	var vo = null;
	var layers = new Array();
	
	for( i = 0; i < max; i++ )
	{
		vo = this.layers[i];
		if( vo.name != p_id )
		{
			layers.push(vo);
		}
	}
	
	this.layers = layers;
};

MapVO.prototype.getLayerVOById = function( p_id )
{
	var i = 0;
	var max = this.layers.length;
	var vo = null;
	
	for( i = 0; i < max; i++ )
	{
		vo = this.layers[i];
		if( vo.name == p_id )
		{
			return vo;
		}
	}
	
	return null;
};


//{
	//"name":"home",
	//"type":"isomap",
	//"layers":[
		//{
			//"lazy":false,
			//"sortFunc":null,
			//"sortArgs":null,
			//"name":"ground",
			//"displayList":[
				//[64,32,0,64,32,1,true,"grass",false],
				//[96,48,0,64,32,1,true,"grass",false]
			//]
		//},
		//{
			//"lazy":false,
			//"sortFunc":null,
			//"sortArgs":null,
			//"name":"ground",
			//"displayList":[
				//[64,32,0,64,32,1,true,"frog",false],
				//[96,48,0,64,32,1,true,"moulin",false]
			//]
		//},
	//]
//}	



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/utils/Loader.js**************************

//***********************************************************************

function Loader()
{
	this.signal = new Signal()
	this._xhr = new XMLHttpRequest();
}

	Loader.LOAD_COMPLETE = "loadComplete";
	
	Loader.prototype.signal = null;
	Loader.prototype._xhr	= null;
	Loader.prototype._data	= null;
	
	Loader.prototype.load = function( p_url, p_async )
	{
		var _this = this;
		p_async = p_async || false;
		
		this._xhr.onreadystatechange = function()
		{
			_this.completeHandler();
		};
		
		this._xhr.open( "GET", p_url, p_async );
		this._xhr.send(null);
	};
	
	
	Loader.prototype.completeHandler = function()
	{
		if( this._xhr.readyState == 4 )
		{
			this._data = this._xhr.responseText;
			this.signal.dispatchEvent( Loader.LOAD_COMPLETE );
		}
	};
	
	Loader.prototype.getData = function()
	{
		return this._data;
	};




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/utils/Sender.js**************************

//***********************************************************************

function Sender()
{
	this.signal = new Signal()
	this._xhr = new XMLHttpRequest();
}

	Sender.LOAD_COMPLETE = "loadComplete";
	
	Sender.prototype.signal = null;
	Sender.prototype._xhr	= null;
	Sender.prototype._data	= null;
	
	Sender.prototype.sendAndLoad = function( p_url, p_data, p_method, p_async )
	{
		var _this = this;
		p_async = p_async || false;
		p_data = p_data || null;
		p_method = ( p_method == "POST" ) ? "POST" : "GET";
		
		this._xhr.onreadystatechange = function()
		{
			_this.completeHandler();
		};
		
		
		
		this._xhr.open( p_method, p_url, p_async );
		
		if( p_method == "POST" )
			 this._xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
		
		this._xhr.send(p_data);
	};
	
	
	Sender.prototype.completeHandler = function()
	{
		if( this._xhr.readyState == 4 )
		{
			this._data = this._xhr.responseText;
			this.signal.dispatchEvent( Sender.LOAD_COMPLETE );
		}
	};
	
	Sender.prototype.getData = function()
	{
		return this._data;
	};




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/ActionMenuMediator.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function ActionMenuMediator( p_view )
{
	this.init( ActionMenuMediator.NAME, p_view );
}

POO.extend( ActionMenuMediator, Mediator );


	// static
	ActionMenuMediator.NAME = "ActionMenuMediator";
	
	
	//private
	ActionMenuMediator.prototype._screen = null;
	
	// public
	ActionMenuMediator.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [p_name, p_data] );
		this._screen = new ActionMenuScreen();
		this.listenNotifications();	
		this._screen.init( this.getViewComponent() );
		this._screen.signal.addListener( ActionMenuScreen.ON_CLICK, this._clickHandler, this );
		this._screen.signal.addListener( ActionMenuScreen.ON_OPEN, this._openProjectHandler, this );
	};
	
	ActionMenuMediator.prototype._openProjectHandler = function(p_url)
	{
		this.getFacade().sendNotification( ApplicationNotification.LOAD_PROJECT, p_url );
	};
	ActionMenuMediator.prototype._clickHandler = function(p_flag)
	{
		switch( p_flag )
		{
			case "close": this.getFacade().sendNotification( ApplicationNotification.UNLOAD_PROJECT ); break;
			case "new": this.getFacade().sendNotification( ApplicationNotification.UNLOAD_PROJECT ); break;
			case "save": this.getFacade().sendNotification( ApplicationNotification.SAVE_PROJECT, {"name":"google"} ); break;
		}
	};
	
	ActionMenuMediator.prototype.listenNotifications = function()
	{
		//this.addNotificationListener( ApplicationNotification.ADD_LAYER, this.onNotification );
	};

	ActionMenuMediator.prototype.onNotification = function( p_notificationType, p_data )
	{
		//var proxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		//
		//switch ( p_notificationType )
		//{
			//case ApplicationNotification.ADD_LAYER:
				//break;
		//}
	};




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/LayersMediator.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function LayersMediator( p_view )
{
	this.init( LayersMediator.NAME, p_view );
}

POO.extend( LayersMediator, Mediator );


	// static
	LayersMediator.NAME = "LayersMediator";
	
	
	//private
	LayersMediator.prototype._screen = null;
	
	// public
	LayersMediator.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [p_name, p_data] );
		this._screen = new LayersScreen();
		this.listenNotifications();	
		this.initLayersList();
	};
	
	LayersMediator.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.ADD_LAYER, 			this.onNotification );
		this.addNotificationListener( ApplicationNotification.SELECT_LAYER, 		this.onNotification );
		this.addNotificationListener( ApplicationNotification.REMOVE_LAYER, 		this.onNotification );
		this.addNotificationListener( ApplicationNotification.CLEAN_LAYERS, 		this.onNotification );
		this.addNotificationListener( ApplicationNotification.DISPLAY_MAP_LAYERS, 	this.onNotification );
	};

	LayersMediator.prototype.onNotification = function( p_notificationType, p_data )
	{
		var proxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var mapProxy = this.getFacade().getProxy( MapProxy.NAME );
		
		switch ( p_notificationType )
		{
				
			case ApplicationNotification.ADD_LAYER:
				this._screen.addLayer( p_data );
				break;
				
			case ApplicationNotification.SELECT_LAYER:
				proxy.currentLayer = p_data;
				break;

			case ApplicationNotification.REMOVE_LAYER:
				this._screen.removeLayer( proxy.currentLayer );
				break;
				
			case ApplicationNotification.CLEAN_LAYERS:
				this._screen.clean();
				break;
				
			case ApplicationNotification.DISPLAY_MAP_LAYERS:
				
				var vo = mapProxy.getMapVOById(proxy.currentMap);
				var layerVO = null;
				var i = 0;
				var max = vo.layers.length;
				
				for( i = 0; i < max ; i++ )
				{
					layerVO = vo.layers[i];
					this._screen.addLayer( layerVO.name );
				}
				
				break;
		}
	};
	
	LayersMediator.prototype.initLayersList = function()
	{
		var container = this.getViewComponent();
		var list = document.getElementById("layersList");
		var addButton = document.getElementById("addLayerButton");
		var removeButton = document.getElementById("removeLayerButton");
		this._screen.init( list, addButton, removeButton );
		this._screen.signal.addListener( LayersScreen.ON_SELECT, this.selectLayerHandler, this );
		this._screen.signal.addListener( LayersScreen.ADD_LAYER, this.addLayerHandler, this );
		this._screen.signal.addListener( LayersScreen.REMOVE_LAYER, this.removeLayerHandler, this );
	};
	
	LayersMediator.prototype.selectLayerHandler = function(p_layerId)
	{
		this.getFacade().sendNotification( ApplicationNotification.SELECT_LAYER, p_layerId );
	};
	
	LayersMediator.prototype.addLayerHandler = function(p_layerId)
	{
		this.getFacade().sendNotification( ApplicationNotification.ADD_LAYER, p_layerId );
	};
	
	LayersMediator.prototype.removeLayerHandler = function(p_layerId)
	{
		this.getFacade().sendNotification( ApplicationNotification.REMOVE_LAYER, p_layerId );
	};




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/LibraryMediator.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function LibraryMediator( p_view )
{
	this.init( LibraryMediator.NAME, p_view );
}

POO.extend( LibraryMediator, Mediator );


	// static
	LibraryMediator.NAME = "LibraryMediator";
	
	
	//private
	LibraryMediator.prototype._screen = null;
	
	// public
	LibraryMediator.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [p_name, p_data] );
		this._screen = new LibraryScreen();
		this.listenNotifications();	
		
		var container = this.getViewComponent();
		var list = document.getElementById("animationList");
		var preview = document.getElementById("preview");
		this._screen.init( list, preview );
		this._screen.signal.addListener( LibraryScreen.ON_SELECT, this.selectAnimationHandler, this );
	};
	
	LibraryMediator.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.LOAD_DATA_COMPLETE, 	this.onNotification );
		this.addNotificationListener( ApplicationNotification.UNLOAD_PROJECT, 		this.onNotification );
	};

	LibraryMediator.prototype.onNotification = function( p_notificationType, p_data )
	{
		switch ( p_notificationType )
		{
			case ApplicationNotification.LOAD_DATA_COMPLETE:
				this.listAnimations();
				break;
				
			case ApplicationNotification.UNLOAD_PROJECT:
				this.clean();
				break;
		}
	};
	
	LibraryMediator.prototype.selectAnimationHandler = function(p_animId)
	{
		var animProxy = this.getFacade().getProxy( AnimationProxy.NAME );
		var animVO = animProxy.getAnimationVOById(p_animId);
		
		if( animVO == null )
			return;
				
		this._screen.renderAnimation( animVO );
		this.getFacade().sendNotification( ApplicationNotification.SELECT_ANIMATION, p_animId );
	};
	
	LibraryMediator.prototype.clean = function()
	{
		this._screen.clean();
	};
	
	LibraryMediator.prototype.listAnimations = function()
	{
		var animProxy = this.getFacade().getProxy( AnimationProxy.NAME );
		var animVO = null;
		var data = animProxy.getData();
		var prop = null;
		var i = 0;
		var max = data.length;
		
		this.clean();
		
		for( ; i < max; i++ )
		{
			vo = data[i];
			this._screen.addAnimation( vo.name );
		}
	}




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/MapLayersMediator.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function MapLayersMediator( p_view )
{
	this.init( MapLayersMediator.NAME, p_view );
}

POO.extend( MapLayersMediator, Mediator );


	// static
	MapLayersMediator.NAME = "MapLayersMediator";
	
	
	//private
	MapLayersMediator.prototype._screen = null;
	
	// public
	MapLayersMediator.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [p_name, p_data] );
		this._screen = new MapLayersScreen();
		this.listenNotifications();	
		this.initMapList();
	};
	
	MapLayersMediator.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.ADD_MAP, 				this.onNotification );
		this.addNotificationListener( ApplicationNotification.SELECT_MAP, 			this.onNotification );
		this.addNotificationListener( ApplicationNotification.DISPLAY_MAPS, 		this.onNotification );
		this.addNotificationListener( ApplicationNotification.REMOVE_MAP, 			this.onNotification );
	};

	MapLayersMediator.prototype.onNotification = function( p_notificationType, p_data )
	{
		var proxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var mapProxy = this.getFacade().getProxy( MapProxy.NAME );
		var i = 0;
		var max = 0;
		var vos = null;
		
		switch ( p_notificationType )
		{
				
			case ApplicationNotification.ADD_MAP:
				this._screen.addMap( p_data );
				break;
				
			// useless already did on selectmapcommand
			case ApplicationNotification.SELECT_MAP:
				proxy.currentMap = p_data;
				break;

			case ApplicationNotification.REMOVE_MAP:
				this._screen.removeMap( proxy.currentMap );
				break;
				
			case ApplicationNotification.DISPLAY_MAPS:
				//this._screen.removeMap( proxy.currentMap );
				
				
				vos = mapProxy.getData();
				max = vos.length;
				
				for( i = 0; i < max; i++ )
				{
					this._screen.addMap( vos[i].name );
				}
				
				break;
		}
	};
	
	MapLayersMediator.prototype.initMapList = function()
	{
		var container = this.getViewComponent();
		var list = document.getElementById("mapsList");
		var addButton = document.getElementById("addMapButton");
		var removeButton = document.getElementById("removeMapButton");
		
		this._screen.init( list, addButton, removeButton );
		this._screen.signal.addListener( MapLayersScreen.ON_SELECT, this.selectMapHandler, this );
		this._screen.signal.addListener( MapLayersScreen.ADD_MAP, this.addMapHandler, this );
		this._screen.signal.addListener( MapLayersScreen.REMOVE_MAP, this.removeMapHandler, this );
		
		this._screen.clean();
	};
	
	MapLayersMediator.prototype.selectMapHandler = function(p_id)
	{
		this.getFacade().sendNotification( ApplicationNotification.SELECT_MAP, p_id );
	};
	
	MapLayersMediator.prototype.addMapHandler = function(p_id)
	{
		this.getFacade().sendNotification( ApplicationNotification.ADD_MAP, p_id );
	};
	
	MapLayersMediator.prototype.removeMapHandler = function()
	{
		this.getFacade().sendNotification( ApplicationNotification.REMOVE_MAP );
	};
	
	
	
	



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/MapMediator.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function MapMediator( p_view )
{
	this.init( MapMediator.NAME, p_view );
}

POO.extend( MapMediator, Mediator );


	// static
	MapMediator.NAME = "MapMediator";

	//private
	MapMediator.prototype._screen = null;
	
	
	// public
	MapMediator.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [p_name, p_data] );
		this.initRenderingContext();
		this.listenNotifications();	
	};
	
	MapMediator.prototype.initRenderingContext = function()
	{
		this._screen = new MapScreen();
		var container = this.getViewComponent();
		this._screen.init( container, 800, 600 );
	};
	
	MapMediator.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.LOAD_DATA_COMPLETE, 	this.onNotification );
		this.addNotificationListener( ApplicationNotification.LOAD_DATA_PROGRESS, 	this.onNotification );
		this.addNotificationListener( ApplicationNotification.ADD_ANIMATION, 		this.onNotification );
		this.addNotificationListener( ApplicationNotification.ADD_LAYER, 			this.onNotification );
		this.addNotificationListener( ApplicationNotification.SELECT_LAYER, 		this.onNotification );
		this.addNotificationListener( ApplicationNotification.REMOVE_LAYER, 		this.onNotification );
		this.addNotificationListener( ApplicationNotification.CLEAN_MAP, 			this.onNotification );
		this.addNotificationListener( ApplicationNotification.DISPLAY_MAP_ANIM, 	this.onNotification );
		this._screen.signal.addListener( MapScreen.ADD_ANIM, this.addAnimHandler, 	this );
	};
	
	MapMediator.prototype.addAnimHandler = function(p_data)
	{
		var proxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var animId = proxy.currentAnim;
		var layerId = proxy.currentLayer;
		
		if( animId == "" )
			return;
		
		this.getFacade().sendNotification( ApplicationNotification.ADD_ANIMATION, {"layerId":layerId,"animId":animId,"x":p_data.x,"y":p_data.y} );
	};

	MapMediator.prototype.onNotification = function( p_notificationType, p_data )
	{
		var animProxy = this.getFacade().getProxy( AnimationProxy.NAME );
		var appProxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var mapProxy = this.getFacade().getProxy( MapProxy.NAME );
		
		switch ( p_notificationType )
		{
			case ApplicationNotification.LOAD_DATA_COMPLETE:
				this.getFacade().sendNotification( ApplicationNotification.LOAD_MAPS_DATA );
				break;
				
			case ApplicationNotification.LOAD_DATA_PROGRESS:
				this._screen.showProgression( p_data.progression );
				break;
				
			case ApplicationNotification.ADD_ANIMATION:
				var animVO = animProxy.getAnimationVOById(p_data.animId);
				this._screen.addSpriteAt( animVO, appProxy.currentLayer, p_data.x, p_data.y );
				break;
				
			case ApplicationNotification.ADD_LAYER:
				this._screen.addLayer( p_data );
				break;
				
			case ApplicationNotification.REMOVE_LAYER:
				this._screen.removeLayer( appProxy.currentLayer );
				break;
				
			case ApplicationNotification.CLEAN_MAP:
				this._screen.clean();
				break;
				
			case ApplicationNotification.DISPLAY_MAP_ANIM:
				
				var vo = mapProxy.getMapVOById(appProxy.currentMap);
				var layerVO = null;
				var i = 0;
				var j = 0;
				var max = vo.layers.length;
				var max2 = 0;
				var animVO = null;
				var spriteData = null;
				
				for( i = 0; i < max ; i++ )
				{
					layerVO = vo.layers[i];
					this._screen.addLayer( layerVO.name );
					
					max2 = layerVO.displayList.length;
					
					for( j = 0; j < max2; j++ )
					{
						spriteData = layerVO.displayList[j];
						animVO = animProxy.getAnimationVOById(spriteData[7]);
						this._screen.addSpriteAt( animVO, layerVO.name, spriteData[0], spriteData[1] );
					}
				}
				
				break;
		}
	};




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/boost/SimpleCulling.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/component/IsoMap.js**************************

//***********************************************************************

function IsoMap()
{
	this._isoData = new Object();
}

POO.extend( IsoMap, Map );


	IsoMap.prototype._isoData = null;
	IsoMap.prototype.cellW = 64;
	IsoMap.prototype.cellH = 32;

	IsoMap.prototype.addSpriteAt = function( p_spr, p_layerId, p_x, p_y )
	{
		var layer = this.getLayer( p_layerId );
		
		if( layer == null )
		{
			return;
		}
		
		var isoCoords = IsoUtils.screenToIso( p_x, p_y );
		var row = isoCoords.row;
		var col = isoCoords.col;
		var remanagedCoords = IsoUtils.isoToScreen( row, col, this.cellW, this.cellH );
		var old = this._getIsoSpriteAt( p_layerId, row, col );
		
		if( old != null )
		{
			this.removeSprite(old);
		}
		
		p_spr.x = remanagedCoords.x;
		p_spr.y = remanagedCoords.y;
		
		this._pushIsoSpriteAt( p_spr, p_layerId, row, col );
		
		layer.displayList.addChild( p_spr );
		p_spr.transformGroup = this.camera.transformGroup;
	};
	
	IsoMap.prototype._pushIsoSpriteAt = function( p_spr, p_layerId, p_row, p_col )
	{
		if( !this._isoData[layerId] )
			this._isoData[layerId] = new Array();
		
		if( this._isoData[layerId][p_row] == undefined )
			this._isoData[layerId][p_row] = new Array();
			
		this._isoData[layerId][p_row][p_col] = p_spr;
	};
	
	IsoMap.prototype._getIsoSpriteAt = function( p_layerId, p_row, p_col )
	{
		if( !this._isoData[layerId] )
			this._isoData[layerId] = new Array();
		
		if( this._isoData[layerId][p_row] == undefined )
			this._isoData[layerId][p_row] = new Array();
			
		if( this._isoData[layerId][p_row][p_col] == undefined )
		{
			return null;
		}
		
		return this._isoData[layerId][p_row][p_col];
	};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/component/Map.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function Map()
{
}



	// private
	
	Map.prototype._renderer 		= null;
	Map.prototype._width			= 1;
	Map.prototype._height			= 1;
	Map.prototype.camera			= null;
	
	
	// public
	Map.prototype.init = function( p_camW, p_camH )
	{
		var camera = new Camera();		
		this.camera = camera;
		
		
		this._renderer = new Renderer2D();
		//render settings
		this._renderer.camera = camera;
		
		//camera
		camera.x = 0;
		camera.y = 0;
		camera.z = 0;
		camera.width = p_camW;
		camera.height = p_camH;
		camera.pivotX = p_camW * 0.5;
		camera.pivotY = p_camH * 0.5;
		camera.pivotZ = 0;
	};
	
	Map.prototype.addLayer = function( p_layerId )
	{
		var canvas = document.createElement("canvas");
		var layer = new Layer();
		
		canvas.width = this.camera.width;
		canvas.height = this.camera.height;
		
		layer.name = p_layerId;
		layer.displayList = new DisplayList();
		layer.canvas = canvas;
		layer.context = layer.canvas.getContext("2d");
		//layer1.lazy = true;
		
		//boost displayList
		
		var boost = new SimpleCulling();
		boost.init();
		layer.displayList.boost = boost;
		layer.sorted = false;
		
		this._renderer.layers.push( layer );
		
		return layer;
	};
	
	Map.prototype.removeLayer = function( p_layerId )
	{
		var layer = this.getLayer( p_layerId );
		
		if( layer == null )
		{
			return null;
		}
			
		var index = this._renderer.layers.indexOf( layer );
		this._renderer.layers.splice( index, 1 );
		return layer;
	};
	
	Map.prototype.getLayer = function( p_layerId )
	{
		var tab = this._renderer.layers;
		var max = tab.length;
		var i = 0;
		var layer = null;
		
		for( i = 0; i < max; i++ )
		{
			layer = tab[i];
			
			if( layer.name == p_layerId )
				return layer;
		}
		
		return null;
	};
	
	Map.prototype.removeSprite = function( p_spr )
	{
		if( p_spr.displayList )
		{
			p_spr.displayList.removeChild( p_spr );
			p_spr.displayList = null;
		}
	};
	
	Map.prototype.addSpriteAt = function( p_spr, p_layerId, p_x, p_y )
	{
		var layer = this.getLayer( p_layerId );
		
		if( layer == null )
		{
			return;
		}
		
		p_spr.x = p_x;
		p_spr.y = p_y;
		
		layer.displayList.addChild( p_spr );
		p_spr.transformGroup = this.camera.transformGroup;
	};
	
	Map.prototype.getSpriteAt = function( p_layerId, p_x, p_y )
	{
		var layer = this.getLayer( p_layerId );
		var spr = null;
		
		if( layer != null )
		{
			spr = layer.displayList.getVisibleChildrenIn( p_x, p_y, 1, 1 )[0];
		}
		
		return spr;
	};
	
	Map.prototype.getLayers = function()
	{
		return this._renderer.layers;
	};

	
	// rendering loop
	Map.prototype.render = function()
	{
		this._renderer.render();
	};
		
	Map.prototype.clean = function()
	{
		this._renderer.layers = new Array();
	};
	
	




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/factory/AnimationFactory.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function AnimationFactory(){}

AnimationFactory.getAnimationFromVO = function( p_vo )
{
	var anim = new Animation();
	anim.animationTime  = p_vo.animTime
	anim.name = p_vo.name;
	anim.frame = 0;
	
	var frames = p_vo.frames;
	var i = 0;
	var max = frames.length;
	
	for( ; i < max; i++ )
	{
		anim.setFrame( i, frames[i].uv, frames[i].tex );
	}
	
	return anim;
};



//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/screen/ActionMenuScreen.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function ActionMenuScreen()
{
}


	//static
	ActionMenuScreen.ON_CLICK	= "onClick";
	ActionMenuScreen.ON_OPEN	= "onOpen";

	// private
	ActionMenuScreen.prototype._container	= null;
	
	// public
	ActionMenuScreen.prototype.signal		= null;
	
	ActionMenuScreen.prototype.init = function( p_container )
	{
		this.signal 		= new Signal();
		this._container 	= p_container;
		this.initMenu();
		this.initLayout();
	};
	
	ActionMenuScreen.prototype.initMenu = function()
	{
		this._container.addEventListener( "click", CallBack.create( this._clickHandler, this ) );
	};
	
	ActionMenuScreen.prototype.initLayout = function()
	{
		document.getElementById("openProjectButton").addEventListener( "click", CallBack.create( this._openProjectHandler, this ) );
	};
	
	ActionMenuScreen.prototype._openProjectHandler = function(event)
	{
		this._hideAllElements();
		var node 	= event.target;
		var url = document.getElementById("projectFilePath").value;
		this.signal.dispatchEvent( ActionMenuScreen.ON_OPEN, [url] ); 
	};
	
	ActionMenuScreen.prototype._clickHandler = function(event)
	{
		var node 	= event.target;
		var flag 	= node.id;
		var visible = event.type == "mouseover";
		
		this._hideAllElements();
		
		switch( flag )
		{
			case "file"		:this._setElementVisible("fileSub");			break;
			case "open"		:this._setElementVisible("openProjectLayout");	break;
			case "events"	:this._setElementVisible("eventSub");			break;
			case "database"	:this._setElementVisible("dbSub");				break;
			case "system"	:this._setElementVisible("sysSub");				break;
			case "help"		:this._setElementVisible("helpSub");			break;
			
			default: 
				this.signal.dispatchEvent( ActionMenuScreen.ON_CLICK, [flag] ); 
				break;
		}
	};
	
	ActionMenuScreen.prototype._hideAllElements = function()
	{
		var elements = ["fileSub","eventSub","dbSub","sysSub","helpSub","openProjectLayout"];
		var i = 0;
		var max = elements.length;
		
		for( i = 0; i < max; i++ )
		{
			document.getElementById(elements[i]).style.display = "none";
		}
	};
	
	ActionMenuScreen.prototype._setElementVisible = function( p_id )
	{
		var element = document.getElementById(p_id);
		
		if( !element.style )
		{
			element.setAttribute("style","");
		}
		
		//var visible = ( element.style.display != "block" );
		//element.style.display = ( visible ) ? "block" : "none";
		element.style.display = "block";
	};


	




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/screen/LayersScreen.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function LayersScreen()
{
}


	//static
	LayersScreen.ON_SELECT			= "onSelect";
	LayersScreen.ADD_LAYER			= "addLayer";
	LayersScreen.REMOVE_LAYER		= "removeLayer";

	// private
	LayersScreen.prototype._list			= null;
	LayersScreen.prototype._addButton		= null;
	LayersScreen.prototype._removeButton	= null;

	LayersScreen.prototype._unSelectAll = function()
	{
		var link = null;
		var linkList = this._list.getElementsByTagName("a");
		var i = 0;
		var max = linkList.length;
		
		for( ; i < max; i++ )
		{
			link = linkList[i];
			link.setAttribute( "class", "" );
		}
	};
	
	
	
	// public
	LayersScreen.prototype.signal		= null;
	
	LayersScreen.prototype.init = function( p_list, p_addButton, p_removeButton )
	{
		this.signal 		= new Signal();
		this._list 			= p_list;
		this._addButton		= p_addButton;
		this._removeButton	= p_removeButton;
		this._list.addEventListener( "click", CallBack.create( this._clickHandler, this ) );
		this._addButton.addEventListener( "click", CallBack.create( this._addHandler, this ) );
		this._removeButton.addEventListener( "click", CallBack.create( this._removeHandler, this ) );
		this.clean();
	};
	
	LayersScreen.prototype._clickHandler = function(event)
	{
		var node 	= event.target;
		var layerId = node.innerHTML;
		this.signal.dispatchEvent( LayersScreen.ON_SELECT, [layerId] );
		this._unSelectAll();
		node.setAttribute("class", "selected");
	};
	
	LayersScreen.prototype._addHandler = function(event)
	{
		var first = ( this._list.children.length == 0 );
		
		var layerId = "layer_"+( this._list.children.length );
		this.signal.dispatchEvent( LayersScreen.ADD_LAYER, [layerId] );
		this._unSelectAll();
		
		if( first )
		{
			var node = this._list.children[0].children[0];
			this.signal.dispatchEvent( LayersScreen.ON_SELECT, [layerId] );
			node.setAttribute("class", "selected");
		}
	};
	
	LayersScreen.prototype._removeHandler = function(event)
	{
		this.signal.dispatchEvent( LayersScreen.REMOVE_LAYER );
		this._unSelectAll();
	};
	

	LayersScreen.prototype.addLayer = function( p_layerId )
	{
		var li 		= document.createElement("li");
		var link 	= document.createElement("a");
		
		var className = ( this._list.children.length % 2 == 0 ) ? "impair" : "pair";
		link.setAttribute( "class", className );
		link.setAttribute( "href", "#" );
		link.innerHTML = p_layerId;
		
		li.appendChild( link );
		this._list.appendChild( li );
	};
	
	LayersScreen.prototype.removeLayer = function( p_layerId )
	{
		var li 		= null;
		var link 	= null;
		var i = 0;
		var max = this._list.children.length;
		var toKill = new Array();
		
		for( i = 0; i < max; i++ )
		{
			li = this._list.children[i];
			link = li.children[0];
			
			if( link.innerHTML == p_layerId )
			{
				toKill.push(li);
			}
		}
		
		max = toKill.length;
		i = 0;
		
		for( i = 0; i < max; i++ )
		{
			this._list.removeChild(toKill[i]);
		}
	};
	
	LayersScreen.prototype.clean = function()
	{
		while( this._list.children.length > 0 )
		{
			this._list.removeChild( this._list.children[0] );
		}
	};
	
	




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/screen/LibraryScreen.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function LibraryScreen()
{
}


	//static
	LibraryScreen.ON_SELECT			= "onSelect";
	LibraryScreen.ADD_ANIMATION		= "addAnimation";

	// private
	LibraryScreen.prototype._list			= null;
	LibraryScreen.prototype._renderer		= null;
	LibraryScreen.prototype._preview		= null;
	LibraryScreen.prototype._addButton		= null;
	
	
	
	// public
	LibraryScreen.prototype.signal		= null;
	

	
	
	LibraryScreen.prototype.init = function( p_list, p_preview )
	{
		var camera = new Camera();	
		var layer = new Layer();
		var canvas = p_preview;
		
		layer.name = "preview";
		layer.displayList = new DisplayList();
		layer.canvas = canvas;
		layer.context = layer.canvas.getContext("2d");
		layer.sorted = false;
		
		this.signal = new Signal();
		this._list = p_list;
		this._preview = p_preview;
		this._renderer = new Renderer2D();
		this._renderer.layers.push( layer );
		this._renderer.camera = camera;
		
		camera.width = p_preview.width;
		camera.height = p_preview.height;
		
		this._list.addEventListener( "click", CallBack.create( this._clickHandler, this ) );
	};
	
	LibraryScreen.prototype._clickHandler = function(event)
	{
		var node = event.target;
		var animId = node.innerHTML;
		this.signal.dispatchEvent( LibraryScreen.ON_SELECT, [animId] );
		this._unSelectAll();
		node.setAttribute("class", "selected");
	};
	
	LibraryScreen.prototype._unSelectAll = function()
	{
		var link = null;
		var linkList = this._list.getElementsByTagName("a");
		var i = 0;
		var max = linkList.length;
		
		for( ; i < max; i++ )
		{
			link = linkList[i];
			link.setAttribute( "class", "" );
		}
	};
	
	LibraryScreen.prototype.renderAnimation = function( p_animVO )
	{
		var anim = AnimationFactory.getAnimationFromVO( p_animVO );
		var spr = new Sprite();
		var layer = this._renderer.layers[0];
		var ratio = p_animVO.height / this._preview.height;
		
		spr.width = p_animVO.width / ratio;
		spr.height = this._preview.height;
		spr.x = ( this._preview.width - spr.width ) * 0.5;
		
		spr.uv 			= anim.data[0].uv;
		spr.textureId 	= anim.data[0].tex;
		
		layer.displayList.removeChildren();
		layer.displayList.addChild(spr);
		this._renderer.render();
	};
	
	
	LibraryScreen.prototype.addAnimation = function( p_animId )
	{
		var li = document.createElement("li");
		var link = document.createElement("a");
		
		var className = ( this._list.children.length % 2 == 0 ) ? "impair" : "pair";
		link.setAttribute( "class", className );
		link.setAttribute( "href", "#" );
		link.innerHTML = p_animId;
		
		li.appendChild( link );
		this._list.appendChild( li );
	};
	
	LibraryScreen.prototype.clean = function()
	{
		var layer = this._renderer.layers[0];
		layer.displayList.removeChildren();
		this._renderer.render();
		
		while( this._list.children.length > 0 )
		{
			this._list.removeChild( this._list.children[0] );
		}
	};
	
	




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/screen/MapLayersScreen.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function MapLayersScreen()
{
}


	//static
	MapLayersScreen.ON_SELECT		= "onSelect";
	MapLayersScreen.ADD_MAP			= "addMap";
	MapLayersScreen.REMOVE_MAP		= "removeMap";

	// private
	MapLayersScreen.prototype._list			= null;
	MapLayersScreen.prototype._addButton	= null;
	MapLayersScreen.prototype._removeButton	= null;

	MapLayersScreen.prototype._unSelectAll = function()
	{
		var link = null;
		var linkList = this._list.getElementsByTagName("a");
		var i = 0;
		var max = linkList.length;
		
		for( ; i < max; i++ )
		{
			link = linkList[i];
			link.setAttribute( "class", "" );
		}
	};
	
	
	
	// public
	MapLayersScreen.prototype.signal		= null;
	
	MapLayersScreen.prototype.init = function( p_list, p_addButton, p_removeButton )
	{
		console.log("init mapslayerscreen");
		this.signal 		= new Signal();
		this._list 			= p_list;
		this._addButton		= p_addButton;
		this._removeButton	= p_removeButton;
		this._list.addEventListener( "click", CallBack.create( this._clickHandler, this ) );
		this._addButton.addEventListener( "click", CallBack.create( this._addHandler, this ) );
		this._removeButton.addEventListener( "click", CallBack.create( this._removeHandler, this ) );
		this.clean();
	};
	
	MapLayersScreen.prototype._clickHandler = function(event)
	{
		var node 	= event.target;
		var mapId = node.innerHTML;
		this.signal.dispatchEvent( MapLayersScreen.ON_SELECT, [mapId] );
		this._unSelectAll();
		node.setAttribute("class", "selected");
	};
	
	MapLayersScreen.prototype._addHandler = function(event)
	{
		var first = ( this._list.children.length == 0 );
		var mapId = "map_"+( this._list.children.length);
		
		this.signal.dispatchEvent( MapLayersScreen.ADD_MAP, [mapId] );
		this._unSelectAll();
		
		if( first )
		{
			var node = this._list.children[0].children[0];
			this.signal.dispatchEvent( MapLayersScreen.ON_SELECT, [mapId] );
			node.setAttribute("class", "selected");
		}
	};
	
	MapLayersScreen.prototype._removeHandler = function(event)
	{
		this.signal.dispatchEvent( MapLayersScreen.REMOVE_MAP );
		this._unSelectAll();
	};
	

	MapLayersScreen.prototype.addMap = function( p_mapId )
	{
		var li 		= document.createElement("li");
		var link 	= document.createElement("a");
		
		var className = ( this._list.children.length % 2 == 0 ) ? "impair" : "pair";
		link.setAttribute( "class", className );
		link.setAttribute( "href", "#" );
		link.innerHTML = p_mapId;
		
		li.appendChild( link );
		this._list.appendChild( li );
	};
	
	MapLayersScreen.prototype.removeMap = function( p_mapId )
	{
		
		var li 		= null;
		var link 	= null;
		var i = 0;
		var max = this._list.children.length;
		var toKill = new Array();
		
		for( i = 0; i < max; i++ )
		{
			li = this._list.children[i];
			link = li.children[0];
			
			if( link.innerHTML == p_mapId )
			{
				toKill.push(li);
			}
		}
		
		max = toKill.length;
		i = 0;
		
		for( i = 0; i < max; i++ )
		{
			this._list.removeChild(toKill[i]);
		}
	};
	
	MapLayersScreen.prototype.clean = function()
	{
		while( this._list.children.length > 0 )
		{
			this._list.removeChild( this._list.children[0] );
		}
	};
	
	




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/screen/MapScreen.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function MapScreen()
{
	this.signal = new Signal();
}



	// private
	MapScreen.prototype._map				= null;
	MapScreen.prototype._mouseTracker 		= null;
	MapScreen.prototype._keyTracker 		= null;
	MapScreen.prototype._container			= null;
	MapScreen.prototype.signal				= null;
	
	// static
	MapScreen.ADD_ANIM					= "addAnim";
	
	
	
	// handlers
	MapScreen.prototype._dblClickHandler = function()
	{
		//var x = this._mouseTracker.localX + this._map.camera.x;
		//var y = this._mouseTracker.localY + this._map.camera.y;
		//this.signal.dispatchEvent( MapScreen.ADD_ANIM, [{"x":x,"y":y}] );
	};
	
	//MapScreen.prototype._upHandler = function(){};
	//MapScreen.prototype._downHandler = function(){};
	
	MapScreen.prototype._setEventListeners = function()
	{		
		 //initialize the mouse/touch tracker
		this._mouseTracker = new MouseTracker(this._container);
		
		//this._mouseTracker.signal.addListener( MouseTracker.MOUSE_UP, this._upHandler, this );
		//this._mouseTracker.signal.addListener( MouseTracker.MOUSE_DOWN, this._downHandler, this );
		this._mouseTracker.signal.addListener( MouseTracker.DOUBLE_CLICK, this._dblClickHandler, this );
		
		this._keyTracker = new KeyboardTracker();
		this._keyTracker.listen(this._container);
	};
	
	
	
	// public
	MapScreen.prototype.init = function( p_container, p_camW, p_camH )
	{
		this._map = new Map();
		this._container = p_container;
		this._map.init( p_camW, p_camH );
		this._setEventListeners();
		this.resume();
	};
	
	
	MapScreen.prototype.zoomAt = function( p_x, p_y, p_zoom )
	{
		var zoom 	= p_zoom;
		var pivotX 	= p_x;
		var pivotY 	= p_y;
		
		this._map.camera.pivotX = pivotX;
		this._map.camera.pivotY = pivotY;
		this._map.camera.zoom 	= zoom;
		
		//TweenNano.to( this._map.camera, 500, {"zoom": zoom} );
	};
	
	
	MapScreen.prototype.addSpriteAt = function( p_animVO, p_layerId, p_x, p_y )
	{
		var anim = AnimationFactory.getAnimationFromVO( p_animVO );
		var spr = new Sprite();
		
		spr.width 		= p_animVO.width;
		spr.height 		= p_animVO.height;
		spr.uv 			= anim.data[0].uv;
		spr.textureId 	= anim.data[0].tex;
		
		anim.sprite = spr;
		
		if( anim.data.length > 0 )
		{
			var rand = ( Math.random() * 1000000 ) >> 0;
			AnimationManager.getInstance().registerAnimation( anim, anim.name+"_"+rand );
		}
		
		this._map.addSpriteAt( spr, p_layerId, p_x, p_y );
	};
	
	
	MapScreen.prototype.addLayer = function( p_layerId )
	{
		var layer = this._map.addLayer( p_layerId );
		this._container.appendChild( layer.canvas );
	};
	
	
	MapScreen.prototype.removeLayer = function( p_layerId )
	{
		var layer = this._map.removeLayer( p_layerId );
		if( layer == null )
		{
			return;
		}
			
		this._container.removeChild( layer.canvas );
	};
	
	
	
	// rendering loop
	MapScreen.prototype.render = function()
	{
		var state = this._keyTracker.getKeyState("a");
		AnimationManager.getInstance().animateAll();
		
		if( this._mouseTracker.down )
		{
			if( state == 0 )
			{
				var x = this._mouseTracker.localX + this._map.camera.x;
				var y = this._mouseTracker.localY + this._map.camera.y;
				this.signal.dispatchEvent( MapScreen.ADD_ANIM, [{"x":x,"y":y}] );
			}
			else
			{
				this._map.camera.x -= ( this._mouseTracker.mouseX - this._mouseTracker.lastX );
				this._map.camera.y -= ( this._mouseTracker.mouseY - this._mouseTracker.lastY );
				this._mouseTracker.lastX = this._mouseTracker.mouseX;
				this._mouseTracker.lastY = this._mouseTracker.mouseY;
			}
		}
		
		var time = new Date().getTime();
		this._map.render();
		time = new Date().getTime() - time;
	};
	
	
	MapScreen.prototype.resume = function()
	{
		FrameManager.getInstance().removeFrameListener( this.render, this );
		FrameManager.getInstance().addFrameListener( this.render, this );
	};
	
	
	MapScreen.prototype.pause = function()
	{
		FrameManager.getInstance().removeFrameListener( this.render, this );
	};
	
	
	MapScreen.prototype.clean = function()
	{
		var layers = this._map.getLayers();
		var layer = null;
		var i = 0;
		var max = layers.length;
		
		for( i = 0; i < max; i++ )
		{
			layer = layers[i];
			this._container.removeChild( layer.canvas );
		}
		
		this._map.clean();
		
		AnimationManager.getInstance().destroy();
	};
	

	

	// loading...
	MapScreen.prototype.showProgression = function( p_progression )
	{
		console.log(p_progression+"%");
		//var context = this._layer.context;
		//context.fillStyle = "white";
		//context.fillRect( 0, 100, 100, 20 );
		//context.fillStyle = "#666666";
		//context.font = '15px sans-serif';
		//context.fillText(p_progression+"%",10,100);
	};
	




//***********************************************************************

//**************************C:\wamp\www\game/src/js/game/view/utils/IsoUtils.js**************************

//***********************************************************************

/**
 * ...
 * @author Thot
 */

function IsoUtils(){}
 
IsoUtils.prototype.screenToIso = function( p_x, p_y, p_cellW, p_cellH )
{
	//var l_coords:Point = new Point( 0, 0);
	
	//p_x -= p_nodeWidth * 0.5;
	
	/**
	 * 
	 * 	p_x = ( col - line ) * ( nodeWidth / 2 );
	 *	p_y = ( col + line ) * ( nodeHeight / 2 );
	 * 
	 *  ( col - line ) = p_x / ( nodeWidth / 2 );
	 *  ( col + line ) = p_y / ( nodeHeight / 2 );
	 * 
	 *   -2 * line = ( col - line ) - ( col + line ) = ( p_x / ( nodeWidth / 2 ) ) - ( p_y / ( nodeHeight / 2 ) );
	 *   line = ( ( p_x / ( nodeWidth / 2 ) ) - ( p_y / ( nodeHeight / 2 ) ) ) / -2;
	 *   
	 * 
	 *   2 * col = col - line + col + line = ( p_x / ( nodeWidth / 2 ) ) + ( p_y / ( nodeHeight / 2 ) );
	 *   col = ( ( p_x / ( nodeWidth / 2 ) ) + ( p_y / ( nodeHeight / 2 ) ) ) / 2
	 * 
	 * 
	 * 
	 */
	
	 var p_nodeHeight = p_cellW;
	 var p_nodeWidth = p_cellH;
	 
	var l_midHeight = p_nodeHeight >> 1;
	var l_midWidth = p_nodeWidth >> 1;
	
	p_x -= l_midWidth;
	
	var l_col = ( ( ( p_x / l_midWidth ) + ( p_y / l_midHeight ) ) * 0.5 ) << 0;
	var l_row = ( ( ( p_x / l_midWidth ) - ( p_y / l_midHeight ) ) * -0.5 ) << 0;
	
	return {"col":l_col, "row":l_row };
};

IsoUtils.prototype.isoToScreen = function(  p_row, p_col, p_cellW, p_cellH )
{
	var x = ( p_col - p_row ) * ( p_cellW * 0.5 );
	var y = ( p_col + p_row ) * ( p_cellH * 0.5 );
	
	return {"x":x, "y":y };
};



